package com.woniuxy.creditsystem.customermag.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.common.bean.CustomerInfo;
import com.woniuxy.creditsystem.common.bean.DtoCus;
import com.woniuxy.creditsystem.common.mapper.CustomerMapper;
import com.woniuxy.creditsystem.common.util.PageRest;
import com.woniuxy.creditsystem.customermag.service.ICustomerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：zhengbin
 * @date ：Created in 2020/12/10
 * @description：客户表impl
 * @modified By：
 * @version: 1.0v
 */
@Transactional(readOnly = true)
@Service
public class CustomerServiceImpl  implements ICustomerService {

    @Resource
    private CustomerMapper customerMapper;

    @Override
    public List<DtoCus> findAll() {
      /**
       * create by: zhengbin
       * description:
       * create time: 2020/12/10
       * @参数 []
       * @return java.util.List<com.woniuxy.creditsystem.common.bean.DtoCus>
       * @修改人和其它信息
       */
        return customerMapper.findAll();
    }


    @Override
    public CustomerInfo findById(long id) {
        /**
         * create by: zhengbin
         * description:
         * create time: 2020/12/10
         * @参数 [id]
         * @return com.woniuxy.creditsystem.common.bean.CustomerInfo
         * @修改人和其它信息
         */
        return customerMapper.findById(id);
    }
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveCustomer(CustomerInfo customerInfo) {
        /**
         * create by: zhengbin
         * description:
         * create time: 2020/12/10
         * @参数 [customerInfo]
         * @return int
         * @修改人和其它信息
         */
        return customerMapper.saveCustomer(customerInfo);
    }
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateCustomer(CustomerInfo customerInfo) {
        /**
         * create by: zhengbin
         * description:
         * create time: 2020/12/10
         * @参数 [customerInfo]
         * @return int
         * @修改人和其它信息
         */

        return customerMapper.updateCustomer(customerInfo);
    }


    @Override
    public PageInfo<DtoCus> findByParams(PageRest req, DtoCus dtoCus) {
       /**
        * create by: zhengbin
        * description:
        * create time: 2020/12/10
        * @参数 [req, dtoCus]
        * @return com.github.pagehelper.PageInfo<com.woniuxy.creditsystem.common.bean.DtoCus>
        * @修改人和其它信息
        */
        System.out.println("page");
        System.out.println(req);

        return PageHelper.startPage(req.getPageNum(),req.getLimit()).doSelectPageInfo(()->customerMapper.findByParams(req,dtoCus));
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updatestRemark(DtoCus dtoCus) {
        return customerMapper.updateRemark(dtoCus);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updatestatus(long id) {
        return customerMapper.updateStatus(id);
    }
}
